//获取table
layui.use('table', function() {
    var table = layui.table;
    var $ = layui.jquery;
    <!--运营首页导航-->
    $('#button_id1').click(function(){
        location.reload();
    });
    $('#button_id2').click(function(){
        //返回上一页并刷新：
        window.location.href = document.referrer;
    });
    $.ajax({
        url: '/SyOperationController/SyCourseReview',//异步调用接口的路径
        type:'post',
        data:'',
        success:function(data){
            getTable(data.data)
        }
    })
    function getTable(data){
        table.render({
            elem: "#demo",//容器
            data:data,
            title: "用户信息表",//标题
            limit: 3,//分页显示条
            width:1100,//宽
            page: {//自定义分页 count总记录 prev上一页 next下一页 refresh刷新 skip表格各种外观，尺寸
                layout: ['count', 'prev', 'page', 'next', 'skip', 'refresh', 'limit'],
                limits: [3, 6, 9, 12, 15],//分页选项
                first: "第一页",
                last: "最后一页",
            },
            cols: [[//定义列
                {
                    field: 'courseId',
                    title: '编号',
                    width: 90,
                    height : 100,
                    height: 'full-110',
                    sort: true,
                    fixed: 'left',
                    templet: function (d) {
                        return d.LAY_INDEX;

                    }
                },
                {
                    field: 'url',
                    title: '课程图片',
                    width: 130,
                    templet: function (d) {
                        return "<img id='img_id' src='"+d.url+"'>" ;
                    }
                },
                {
                    field: 'course_name',
                    title: '课程名称',
                    width: 150
                },
                {
                    field: 'course_nprice',
                    title: '课程价格',
                    width: 150
                },
                {
                    field: 'create_id',
                    title: '上传人员',
                    width: 120
                },
                {
                    field: 'class_id',
                    title: '课程分类',
                    width: 120
                },
                {
                    field: 'course_cstatus',
                    title: '审核状态',
                    width: 120
                },
                {
                    title: '操作',
                    width: 205,
                    templet : function(d) {
                        return "<a style='color: green' onclick='getChKan("+d.courseId+")'>查看</a>"+"<a style='margin-left: 20px;color: green' onclick='getSetails("
                            + d.courseId
                            + ")'>"
                            +"审核"
                            + "</a>";
                    }
                }]]

        })
    }
    //打开商品审核页面
    getSetails=function(courseId) {
        stringify("s",courseId)
        layer.open({
            type: 2,//弹出层的类型
            title: "商品审核",
            area: ['670px', '510px'],
            offset: ['114px', '518px'],
            shade: 0.5,
            content: "CommodityReview.html",
            success: function (layero, index) {
                var layer = layui.layer;
            }
        })
    }

    $('#button_id3').click(function(){
        layer.open({
            type: 2,//弹出层的类型
            title: "商品审核",
            area: ['700px', '600px'],
            offset: ['114px', '518px'],
            shade: 0.5,
            content: "CourseReviewAdvancedSearch.html",
            success: function (layero, index) {
                var layer = layui.layer;
            }
        })

    })
    $('#button_id4').click(function(){
        var x=  document.getElementById("input_id3")//获取输入框元素
        var Class=$("#select_id option:selected").val();
        var Class2=$("#select_id2 option:selected").val();
        f(x.value,Class,Class2);
    });
    function  f(kecheng,aClass,aClass2) {
        $.ajax({
            url:'/SyOperationController/ReviewAdvancedSearch',
            type:'post',
            data:{"kecheng":kecheng,"aClass":aClass,"aClass2":aClass2},
            success:function(data){
                getTable(data.data)
            }
        })
    }
    //存值
    stringify=function (obj,data){

        return window.localStorage.setItem(obj, JSON.stringify(data));

    }
    //取值
    parse=function (obj){
        return JSON.parse(localStorage.getItem(obj));
    }
    var da=parse("data");
    if(da!=null){
        getTable(da);
    }
    getChKan=function(id){
        stringify("ChaKan_id",id)
        $.ajax({
            url: '/SyOperationController/CommodityChindChaKan',
            type: 'post',
            data: {"id": id},
            success: function (data) {
                console.log(data.data[0])
                layer.open({
                    type: 2,//弹出层的类型
                    title: "商品审核",
                    area: ['700px', '600px'],
                    offset: ['114px', '518px'],
                    shade: 0.5,
                    content: "CommodityReviewChind.html",
                    success: function (layero, index) {
                        var layer = layui.layer;
                        var obj = layero.find('iframe').contents();
                        obj.find("input[name=productCode]").val(data.data[0].product_code)
                        obj.find("input[name=productName]").val(data.data[0].product_name)
                        obj.find("input[name=currentpriceProduct]").val(data.data[0].currentprice_product)
                        if(data.data[0].product_sate==0){
                            obj.find("input[name=condition]").val("已删除")
                        }else if(data.data[0].product_sate==1){
                            obj.find("input[name=condition]").val("上架")
                        }else{
                            obj.find("input[name=condition]").val("审核中")
                        }
                        obj.find("input[name=categoryId]").val(data.data[0].category_id)
                        obj.find("input[name=productDescription]").val(data.data[0].product_description)
                        obj.find("input[name=productLabel]").val(data.data[0].search_keywords)
                    }
                })
            }
        })

    }
})